from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from meiduo_mall import settings

# 4.1 对a标签的链接进行加密处理
def generic_email_verify_token(user_id):

    # 创建实例
    s = Serializer(secret_key=settings.SECRET_KEY,expires_in=3600*24)

    # 加密数据
    data = s.dumps({'user_id':user_id})

    # 返回数据
    return data.decode()



# 解密
def check_verify_token(token):
    # 创建实例
    s = Serializer(secret_key=settings.SECRET_KEY, expires_in=3600 * 24)

    # 解密数据，可能有异常
    try:
        result = s.loads(token)
    except Exception as e:
        return None

    # 获取数据
    return result.get('user_id')